package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controlador.Controlador;
import Controlador.ControladorProveedor;
import beans.Proveedor;





/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ProveedoresFrame extends Vista {

	{
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JFrame ventana = new JFrame();
	
	

	public static void main(String[] args) {
		ProveedoresFrame p = new ProveedoresFrame();
		Controlador proveedor= new ControladorProveedor(p);
		p.addcontroladorproveedor(proveedor);
		
	} 
	

	public ProveedoresFrame()
	{
		super();
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			{
				jLabel1 = new JLabel();
				ventana.getContentPane().add(jLabel1, BorderLayout.CENTER);
				jLabel1.setText("Proveedores");
				jLabel1.setPreferredSize(new java.awt.Dimension(489, 14));
				ventana.setTitle("Crear Proveedor");
			}
			{
				jPanel1 = new JPanel();
				ventana.getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				jPanel1.setPreferredSize(new java.awt.Dimension(470, 164));
				{
					txtcondcompra = new JLabel();
					jPanel1.add(txtcondcompra);
					txtcondcompra.setText("Cond compra:");
					txtcondcompra.setBounds(32, 35, 87, 16);
				}
				{
					txtrs = new JLabel();
					jPanel1.add(txtrs);
					txtrs.setText("Razon Social:");
					txtrs.setBounds(33, 69, 87, 16);
				}
				{
					JButtonaceptar = new JButton();
					jPanel1.add(JButtonaceptar);
					JButtonaceptar.setText("Aceptar");
					JButtonaceptar.setBounds(138, 116, 88, 23);
					JButtonaceptar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							JButtonaceptarActionPerformed(evt);
						}
					});
				}
				{
					JButtoncancelar = new JButton();
					jPanel1.add(JButtoncancelar);
					JButtoncancelar.setText("Cancelar");
					JButtoncancelar.setBounds(277, 116, 95, 23);
					JButtoncancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btncancelarActionPerformed(evt);
						}
					});
				}
				{
					condcompra = new JTextField();
					jPanel1.add(condcompra);
					condcompra.setBounds(138, 33, 109, 23);
				}
				{
					razonsoc = new JTextField();
					jPanel1.add(razonsoc);
					razonsoc.setBounds(138, 67, 242, 23);
				}
				{
					jLabelcrearProv = new JLabel();
					jPanel1.add(jLabelcrearProv);
					jLabelcrearProv.setText("Crear Proveedor");
					jLabelcrearProv.setBounds(183, 0, 94, 16);
				}
				ventana.setLocationRelativeTo(null);
				ventana.setVisible(true);
				ventana.pack();
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void borrarTextos() {
		condcompra.setText("");
		razonsoc.setText("");
	}
	
	private void JButtonaceptarActionPerformed(ActionEvent evt) {
		Proveedor prov;
		prov=((ControladorProveedor)getControladorProveedor()).buscarProveedor(razonsoc.getText());
		if (prov==null){
			if (razonsoc.getText().length()==0 || condcompra.getText().length()==0){
				System.out.println("Debe completar los campos");
			}
			else {
				((ControladorProveedor)getControladorProveedor()).crearProveedor(razonsoc.getText(), condcompra.getText());
				borrarTextos();
			}
		}
		
		
	}
	private JPanel jPanel1;
	private JLabel jLabelcrearProv;
	private JTextField condcompra;
	private JLabel jLabel1;
	private JTextField razonsoc;
	private JButton JButtoncancelar;
	private JButton JButtonaceptar;
	private JLabel txtrs;
	private JLabel txtcondcompra;



	public JFrame getVentana() {
		return ventana;
	}

	private void btncancelarActionPerformed(ActionEvent evt) {
		this.ventana.dispose();
	}

}


